package com.ruoyi.backend.controller;

import com.ruoyi.backend.domain.SysDictData;
import com.ruoyi.backend.service.ISysDictDataService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 服务类别Controller
 *
 * @author 王冰冰
 * @date 2025-03-18
 */
@RestController
@RequestMapping("/serviceCategory")
public class SysDictDataController extends BaseController {
    @Autowired
    private ISysDictDataService sysDictDataService;

    /**
     * 查询服务类别列表
     */
    @RequiresPermissions("serviceManagement:serviceCategory:list")
    @GetMapping("/list")
    public TableDataInfo list(SysDictData sysDictData) {
        startPage();
        List<SysDictData> list = sysDictDataService.selectSysDictDataList(sysDictData);
        return getDataTable(list);
    }

    /**
     * 导出服务类别列表
     */
    @RequiresPermissions("serviceManagement:serviceCategory:export")
    @Log(title = "服务类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysDictData sysDictData) {
        List<SysDictData> list = sysDictDataService.selectSysDictDataList(sysDictData);
        ExcelUtil<SysDictData> util = new ExcelUtil<SysDictData>(SysDictData.class);
        util.exportExcel(response, list, "服务类别数据");
    }

    /**
     * 获取服务类别详细信息
     */
    @RequiresPermissions("serviceManagement:serviceCategory:query")
    @GetMapping(value = "/{dictCode}")
    public AjaxResult getInfo(@PathVariable("dictCode") Long dictCode) {
        return success(sysDictDataService.selectSysDictDataByDictCode(dictCode));
    }

    /**
     * 新增服务类别
     */
    @RequiresPermissions("serviceManagement:serviceCategory:add")
    @Log(title = "服务类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysDictData sysDictData) {
        return toAjax(sysDictDataService.insertSysDictData(sysDictData));
    }

    /**
     * 修改服务类别
     */
    @RequiresPermissions("serviceManagement:serviceCategory:edit")
    @Log(title = "服务类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysDictData sysDictData) {
        return toAjax(sysDictDataService.updateSysDictData(sysDictData));
    }

    /**
     * 删除服务类别
     */
    @RequiresPermissions("serviceManagement:serviceCategory:remove")
    @Log(title = "服务类别", businessType = BusinessType.DELETE)
    @DeleteMapping("/{dictCodes}")
    public AjaxResult remove(@PathVariable Long[] dictCodes) {
        return toAjax(sysDictDataService.deleteSysDictDataByDictCodes(dictCodes));
    }
}